
/**
 * author:MengYuan
 * desc:公共机制
 * */
//获取浏览器地址栏参数的
$.getUrlParam = function (name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return decodeURI(r[2]); return null;
}

var common = {};

//弹出框模板构造方法
//用的时候，common.lightBox.showMessage("你确定要删除此条信息吗？")
common.lightBox={
    el:'',
    initTemplate:function(message){
        if(this.el.length>0){
            this.el.remove();
        }
        var a = [],$this = this;
        a.push('<div class="modal fade" id="showModalMessageBox">');
        a.push('    <div class="modal-dialog">');
        a.push('        <div class="modal-content">');
        a.push('            <div class="modal-header">');
        a.push('                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>');
        a.push('                <h4 class="modal-title">提示</h4>');
        a.push('            </div>');
        a.push('            <div class="modal-body">');
        a.push('                <p>'+message+'</p>');
        a.push('            </div>');
        a.push('            <div class="modal-footer">');
        a.push('                <button type="button" class="btn btn-primary" data-dismiss="modal" style="background-color: #f2ae43;border-color: #f2ae43;" >关闭</button>');
        a.push('            </div>');
        a.push('        </div>');
        a.push('    </div>');
        a.push('</div>');
        var alertBox = a.join('');
        $(document.body).append(alertBox);
        var showModal = $("#showModalMessageBox");
        this.el = showModal;
    },
    showMessage:function(info,callback){
        this.initTemplate(info);
        this.el.modal("show");
    },
    showLoading:function () {
        if($("#loading").length>0){
            $("#loading").show();
            return;
        }
        var loadingHtml = "<div id='loading' style='width: 100%;height: 100%;position:fixed;top:0;z-index:999;background-color: black;opacity:0.5;'><img src='../images/ajaxLoading.gif' style='margin: 20% 48%'/><div>";
        $(document.body).append(loadingHtml);

    },
    hideLoading:function () {
        if($("#loading").length>0){
            $("#loading").hide();
            return;
        }
    }
};
/**
 * func:主要用于查询数据
 * desc : 封装公共的请求方法
 * param:1.url 请求的地址 2.param 请求的参数 3.请求成功后的回调方法
 * */
$.getRequest = function (url,param,callback) {
    if(typeof param == "function"){
        callback = param;
        param = "";
    }
    $.ajax({ //请求登录处理页
        url: url,
        dataType: "json",
        type:"get",
        data:param,
        xhrFields: {
            withCredentials: true
        },
        crossDomain: true,
        success: function (data) {
            callback && callback(data);
        },
        error: function (msg) {
            common.lightBox.showMessage("接口请求失败."+msg);
        }
    });
}

/**
 * func:主要用于提交表单
 * desc : 封装公共的请求方法
 * param:1.url 请求的地址 2.param 请求的参数 3.请求成功后的回调方法
 * */
$.postRequest = function (url,param,callback) {
    if(typeof param == "function"){
        callback = param;
        param = "";
    }
    $.ajax({ //请求登录处理页
        url: url,
        dataType: "json",
        type:"post",
        data:param,
        xhrFields: {
            withCredentials: true
        },
        crossDomain: true,
        success: function (data) {
            callback && callback(data);
        },
        error: function (msg) {
            common.lightBox.showMessage("接口请求失败."+msg);
        }
    });
}
//获取当前浏览器的分页参数
window.cachUrlPageNum = parseInt($.getUrlParam("p") || 1);
//设置浏览器地址
function setPageParam(pageNum) {
    var url = "";
    //用正则匹配url里面是否包含"p=",如果包含的话,需要把后面的值替换了
    if(/[\?|\&]p=[\d]*/.test(location.search)){
        url = location.search.replace(/p=([\d]*)/,"p="+pageNum);
    }else{
        if(location.search){
            url = location.search + "&p=" + pageNum;
        }else{
            url = "?p=" + pageNum;
        }
    }
    window.history.replaceState("","",url);
}

function showmenu(){
    if($(".leftnav").css('display') == "none"){
        $(".container-fluid").css('marginLeft',"212px");
        $(".leftnav").css('display',"block");
    }else if($(".leftnav").css("display") =="block"){
        $(".leftnav").css('display',"none");
        $(".container-fluid").css('marginLeft',"0");
    }

}

var majiangurl="http://dailibak.zshj66.com/";
var pageurl="http://daili.zshj66.com/";


